#include "TcpServer.h"

TcpServer::TcpServer(boost::asio::io_service& io_service)
    : acceptor_( io_service, tcp::endpoint(tcp::v4(), 9000))
{
	start_accept();
}

TcpServer::~TcpServer(void)
{
}

void TcpServer::start_accept()
  {
    TcpConnection::pointer new_connection =
      TcpConnection::create(acceptor_.get_io_service());

    acceptor_.async_accept(new_connection->socket(),
        boost::bind(&TcpServer::handle_accept, this, new_connection,
          boost::asio::placeholders::error));
  }

void TcpServer::handle_accept(TcpConnection::pointer new_connection,
      const boost::system::error_code& error)
{
	if (!error)
	{
		new_connection->start();
	}

	start_accept();
}
